﻿using System;


public class Circle
{
  
    private double _radius;

   
    public double Radius
    {
        get => _radius;
        set
        {
            if (value <= 0)
                throw new ArgumentException("半径必须是正数", nameof(value));
            _radius = value;
        }
    }


    public Circle(double radius)
    {
        Radius = radius; // 使用属性的setter进行验证
    }

    
    public double CalculateCircumference()
    {
        return 2 * Math.PI * _radius;
    }

    public double CalculateArea()
    {
        return Math.PI * _radius * _radius;
    }
}

public class Program
{
    public static void Main()
    {
        try
        {
            // 创建一个半径为5的圆
            Circle circle = new Circle(5);

            Console.WriteLine($"半径为 {circle.Radius} 的圆:");
            Console.WriteLine($"周长: {circle.CalculateCircumference():F2}");
            Console.WriteLine($"面积: {circle.CalculateArea():F2}");

            // 修改半径并重新计算
            circle.Radius = 7;
            Console.WriteLine($"\n半径修改为 {circle.Radius} 后的圆:");
            Console.WriteLine($"周长: {circle.CalculateCircumference():F2}");
            Console.WriteLine($"面积: {circle.CalculateArea():F2}");
        }
        catch (ArgumentException ex)
        {
            Console.WriteLine($"错误: {ex.Message}");
        }
    }
}
